package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.ZhengquanMapper;
import work.xiaohong.gupiao.pojo.Zhengquan;
import work.xiaohong.gupiao.service.ZhengquanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZhengquanServiceImpl implements ZhengquanService {

    @Autowired
    private ZhengquanMapper zhengquanMapper;


    /**
     * 条件+分页查询Zhengquan
     * @param zhengquan 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Zhengquan> findPage(Zhengquan zhengquan, int page, int size){
        // 构建查询条件
        QueryWrapper<Zhengquan> queryWrapper = new QueryWrapper<Zhengquan>(zhengquan);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return zhengquanMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Zhengquan
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Zhengquan> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return zhengquanMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Zhengquan
     * @param zhengquan
     * @return
     */
    @Override
    public List<Zhengquan> findList(Zhengquan zhengquan){
        // 构建查询条件
        QueryWrapper<Zhengquan> queryWrapper = new QueryWrapper<Zhengquan>(zhengquan);
        // 查询数据
        return zhengquanMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Zhengquan
     * @param id
     */
    @Override
    public void delete(Integer id){
        zhengquanMapper.deleteById(id);
    }

    /**
     * 根据ID修改Zhengquan
     * @param zhengquan
     */
    @Override
    public void update(Zhengquan zhengquan){
        zhengquanMapper.updateById(zhengquan);
    }

    /**
     * 增加Zhengquan
     * @param zhengquan
     */
    @Override
    public void add(Zhengquan zhengquan){
        zhengquanMapper.insert(zhengquan);
    }

    /**
     * 根据ID查询Zhengquan
     * @param id
     * @return
     */
    @Override
    public Zhengquan findById(Integer id){
        return  zhengquanMapper.selectById(id);
    }

    /**
     * 查询全部Zhengquan数据
     * @return
     */
    @Override
    public List<Zhengquan> findAll() {
        return zhengquanMapper.selectList(null);
    }
}
